package io.github.wjehovah.yyn.utils;

import android.content.Context;
import android.content.SharedPreferences;

import io.github.wjehovah.yyn.App;


/**
 * Created by wuyong on 15/7/24.
 */
public class SharedPrefUtils {

    private static SharedPreferences sharedPreferences;

    static {
        sharedPreferences = App.getContext().getSharedPreferences("update_history", Context.MODE_PRIVATE);
    }


    public static void save(String key, Object value) {
        if (value instanceof Integer) {
            sharedPreferences.edit().putInt(key, (Integer) value).apply();
        } else if (value instanceof String) {
            sharedPreferences.edit().putString(key, (String) value).apply();
        } else if (value instanceof Boolean) {
            sharedPreferences.edit().putBoolean(key, (Boolean) value).apply();
        }
    }

    public static int getInt(String key, int defValue) {
        return sharedPreferences.getInt(key, defValue);
    }

    public static String getString(String key, String defValue) {
        return sharedPreferences.getString(key, defValue);
    }

    public static boolean getBoolean(String key, boolean defValue) {
        return sharedPreferences.getBoolean(key, defValue);
    }
}
